/**
 *
 */
package com.nightwalker.xsite.customtags;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import com.nightwalker.xsite.bean.AutorBean;
import com.nightwalker.xsite.bean.ObraBean;
import com.nightwalker.xsite.controller.ObraController;
import com.nightwalker.xsite.delegate.AutorDelegate;

/**
 * RecuperarAutoresCT
 * <br><br>
 * <b>Description:</b>Tag para recuperar os autores.
 * <br><br>
 * Created in Feb 9, 2008 12:49:56 AM
 * <br>
 * <b>version:</b>1.0
 * <br>
 * <b>Modifications:</b>
 */
public class RecuperarAutoresCT extends TagSupport{
	private static final long serialVersionUID = 1L;
	private static Logger log = Logger.getLogger(RecuperarAutoresCT.class);

	public int doStartTag(){
		ObraController obraController = (ObraController)pageContext.getRequest().getAttribute("obraController");

		ObraBean obra = obraController.getObra();
		SelectItem item = null;

		AutorBean autor = new AutorBean();
		AutorDelegate autorDelegate = new AutorDelegate();

		log.debug("Recuperando os tipos");
		autorDelegate.recuperarAutores(autor);
		List<SelectItem> autores = new ArrayList<SelectItem>();

		for (AutorBean autorIn : autor.getAutores()) {
			item = new SelectItem();
			item.setLabel(autorIn.getNome());
			item.setValue(autorIn.getId());

			autores.add(item);
		}
		obra.setItens(autores);

		return SKIP_BODY;
	}

}
